package main

import "fmt"

//阶乘
func factorial1(n int) int {
	r := 1
	for i := n; i > 0; i-- {
		r *= i
	}
	return r
}

func factorial2(n int) int {
	if n == 1 {
		return 1
	}
	return n * factorial2(n-1)
}

func factorial3(n int) int {
	out := make(chan int)
	go func() {
		out <- factorial2(n)
		close(out)
	}()
	return <-out
}

func main() {
	//r := factorial1(5)
	//r := factorial2(5)
	r := factorial3(5)
	fmt.Println(r)
}
